<?php
/* @var $this ProductController */
/* @var $model Product */
/* @var $form CActiveForm */
?>
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/views/form-product.css" />
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'product-form',
	'htmlOptions' => array(
        'enctype' => 'multipart/form-data',
    ),
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'product_name'); ?>
		<?php echo $form->textField($model,'product_name',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'product_name'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'cost'); ?>
		<?php echo $form->textField($model,'cost'); ?>
		<?php echo $form->error($model,'cost'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'cost_sale'); ?>
		<?php echo $form->textField($model,'cost_sale'); ?>
		<?php echo $form->error($model,'cost_sale'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'image_link'); ?>
		<?php echo CHtml::activeFileField($model,'image_link',array('id'=>'imgInp')); ?>
		<?php echo $form->error($model,'image_link'); ?>
	</div>
	<?php
		if (!empty($model->image_link)) {
			echo CHtml::image(Yii::app()->request->baseUrl.'/images/Product/'.$model->image_link,$model->product_name, array('id'=>'preview'));
		} else {
			echo "<img id='preview' src='http://placehold.it/140x100' alt='preview de la imagen 123' />";

		}
	?>
	<!-- <img id="preview" src="http://placehold.it/140x100" alt="preview de la imagen" /> -->
	<div class="row row-image">
		<div class="image-product">
			<?php echo $form->labelEx($modelImage,'image_1'); ?>
			<?php echo CHtml::activeFileField($modelImage,'image_1',array('id'=>'image_1')); ?>
			<?php echo $form->error($modelImage,'image_1'); ?>
			<?php
				if (!empty($modelImage->image_1)) {
					echo CHtml::image(Yii::app()->request->baseUrl.'/images/Product/'.$modelImage->image_1,$model->product_name,array('id'=>'preview_1'));
				} else {
					echo "<img id='preview_1' src='http://placehold.it/140x100' alt='preview de la imagen 123' />";

				}
			?>
		</div>
		
		<div class="image-product">
			<?php echo $form->labelEx($modelImage,'image_2'); ?>
			<?php echo CHtml::activeFileField($modelImage,'image_2',array('id'=>'image_2')); ?>
			<?php echo $form->error($modelImage,'image_2'); ?>
			<?php
				if (!empty($modelImage->image_2)) {
					echo CHtml::image(Yii::app()->request->baseUrl.'/images/Product/'.$modelImage->image_2,$model->product_name,array('id'=>'preview_2'));
				} else {
					echo "<img id='preview_2' src='http://placehold.it/140x100' alt='preview de la imagen 123' />";

				}
			?>
		</div>
		<div class="image-product">
			<?php echo $form->labelEx($modelImage,'image_3'); ?>
			<?php echo CHtml::activeFileField($modelImage,'image_3',array('id'=>'image_3')); ?>
			<?php echo $form->error($modelImage,'image_3'); ?>
			<?php
				if (!empty($modelImage->image_3)) {
					echo CHtml::image(Yii::app()->request->baseUrl.'/images/Product/'.$modelImage->image_3,$model->product_name,array('id'=>'preview_3'));
				} else {
					echo "<img id='preview_3' src='http://placehold.it/140x100' alt='preview de la imagen 123' />";

				}
			?>
		</div >
		<div class="image-product-right">
			<?php echo $form->labelEx($modelImage,'image_4'); ?>
			<?php echo CHtml::activeFileField($modelImage,'image_4',array('id'=>'image_4')); ?>
			<?php echo $form->error($modelImage,'image_4'); ?>
			<?php
				if (!empty($modelImage->image_4)) {
					echo CHtml::image(Yii::app()->request->baseUrl.'/images/Product/'.$modelImage->image_4,$model->product_name,array('id'=>'preview_4'));
				} else {
					echo "<img id='preview_4' src='http://placehold.it/140x100' alt='preview de la imagen 123' />";

				}
			?>
		</div>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'category_id'); ?>
		<?php echo $form->dropDownList($model,'category_id',$listCategory); ?>
		<?php echo $form->error($model,'category_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'product_sale'); ?>
		<?php echo $form->checkBox($model,'product_sale'); ?>
		<?php echo $form->error($model,'product_sale'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'product_new'); ?>
		<?php echo $form->checkBox($model,'product_new'); ?>
		<?php echo $form->error($model,'product_new'); ?>
	</div>

	<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl;?>/js/ckeditor/ckeditor.js"></script>
	<div class="row">
		<?php echo $form->labelEx($model,'content'); ?>
		<?php echo $form->textArea($model,'content',array('rows'=>10, 'id'=>'text_content')); ?>
		<?php echo $form->error($model,'content'); ?>
	</div>
	<script type="text/javascript">
		CKEDITOR.replace('text_content',
			{
				filebrowserBrowseUrl :  '/thanhshop/js/ckeditor/ckfinder/ckfinder.html' , 
			    filebrowserImageBrowseUrl :  '/thanhshop/js/ckeditor/ckfinder/ckfinder.html?Type=Images' , 
			    filebrowserFlashBrowseUrl :  '/thanhshop/js/ckeditor/ckfinder/ckfinder.html?Type=Flash' , 
			    filebrowserUploadUrl :  '/thanhshop/js/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files' , 
			    filebrowserImageUploadUrl :  '/thanhshop/js/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images' , 
			    filebrowserFlashUploadUrl :  '/thanhshop/js/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash' 

			});
	</script>

	<div class="row">
		<?php echo $form->labelEx($model,'description'); ?>
		<?php echo $form->textArea($model,'description',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'description'); ?>
	</div>
	
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl;?>/js/upload-image.js"></script>